<template>
  <div class="goods-size-content">

    <el-button @click="showEditDialog()" type="primary">{{$t('stock.Modify inventory')}}</el-button>

    <el-dialog
      :visible.sync="dialog"
      width="600px"
      class="goods-size-dialog"
      :title="$t('stock.修改库存')"
      append-to-body
    >
      <div style="margin-top: -20px; font-size: 16px; color: black; text-align: left;">
        <div style="margin-left: 66px; margin-top: 10px;">
          <span>{{$t('stock.当前库存')}}： {{ this.goodsRow.stockNum }}</span>
        </div>
        <div style="margin-left: 35px; margin-top: 20px;">
          <span>
            {{$t('stock.修改后的库存')}}：
          <el-input-number v-model="stockNum" :min="1" :max="max"></el-input-number>
          </span>
        </div>
      </div>
      <div slot="footer">
        <el-button size="small" @click="dialog = false">{{$t('common.cancel')}}</el-button>
        <el-button size="small" type="primary" @click="submitStockNum()" :loading="loading">{{$t('common.save')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {savePacketStockNum} from "@/api/stock";

export default {
  name: "goodsSize",
  mixins: [],
  props:{
    goodsRow: {
      type: Object,
      required: true,
    },
    suitId: {
      type: Number,
      required: true,
    }
  },
  computed:{

  },
  data(){
    return {
      max: 999999, // 设置一个最大值，避免用户乱填 导致接口异常
      stockNum: 0,
      dialog: false,
      loading: false,
    }
  },
  methods: {
    showEditDialog(){
      this.stockNum = this.goodsRow.stockNum
      this.dialog = true
    },
    // 提交表单数据
    submitStockNum(){
      this.loading = true
      const postData = {
        suitId: this.goodsRow.id,
        stockNum: this.stockNum,
      }
      savePacketStockNum(postData)
        .then(res=>{
          this.loading = false
          this.dialog = false
          this.$successMessage(res.message)
        })
    },
  }
}

</script>

<style scoped lang="scss">
.goods-size-dialog{
  text-align: left;
  .goods-size-dialog-content{
    margin-top: -25px;
    .goods-size-dialog-sub-title{
      font-size: 14px;
    }
    .goods-size-tips{
      font-size: 14px;
      margin: 3px 0 10px;
    }

    .goods-size-dialog-form{
      .weight-input{
        width: 100px;
      }
      .size-input-box{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        .size-input{
          width: 100px;
          ::v-deep .el-input-group__append{
            padding: 0 15px !important;
          }
        }
      }

    }
  }
}
</style>
